Return to doc.sitecore.com

3.  Custom Field Types
Prev

Each of the field types described above provides some advantages and disadvantages over others.  For instance checklists allows multiple selections but does not allow the user to order those selections and is difficult to use with a long list of items; multilist is easier to use for long lists and allows the user to order the selection but does not allow the user to upload.  Link allows the user to upload but would also allow the user to reference something that is not a media item.  If the requirement is that the field must allow the user to upload and must only reference media items, a custom field type based on the default Link may be most appropriate.  To create the custom field:

  1. In Content Editor navigate to System/Field types.
  2. Duplicate Link as MediaLink.
  3. Open the Menu item under MediaLink.

Use this field type in Sitecore templates for fields which should only reference media.  Fields of this type will reuse the UI from and have all of the features of the underlying Link field type such as support for upload and The Source Property, but will provide a UI that only supports selection of media items.  The templating UI appears as follows:

/upload/sdn5/articles 2/media/referencing binary items/binary_items1.jpg 

Selecting the button results in a UI which allows selection or upload.  The user is not able to navigate above the path defined by The Source Property:

/upload/sdn5/articles 2/media/referencing binary items/binary_items2.png

As the field is based on the Link field, the same techniques are used for accessing field values – retrieve the media item using its ID, then retrieve the path field from that media item.


Prev